<template>
    <div>
        <h3 style="margin: 10px 0;">防御报告列表</h3>
        <Table border :columns="defeFileCol" :data="row"></Table>
    </div>
</template>
<script>
    export default {
        props:{
            row:Array,
        },
        data () {
            return {
                defeFileCol:[
                    {
                        title:'序号',
                        type:'index',
                        width:60,
                        align:'center'
                    },
                    {
                        title:"名称",
                        key:'name',
                    },
                    {
                        title:"创建者",
                        key:'creatorName',
                    },
                    {
                        title:"用户类型",
                        key:'userType',
                    },
                    // {
                    //     title:"报告类型",
                    //     key:'fileType',
                    //     render:(h,params)=>{
                    //         let text = ''
                    //         if(params.row.fileType === 'ORIGINAL'){
                    //             text = '原报告'
                    //         }else if(params.row.fileType === 'SUPPLEMENT'){
                    //             text = '补充报告'
                    //         }
                    //         return h('div',text)
                    //     }
                    // },
                    {
                        title:'下载',
                        key:'down',
                        render:(h,params)=>{
                            return h('div',[
                                h('Button', {
                                    props: {
                                        type: 'primary',
                                        size: 'small',
                                    },
                                    on: {
                                        'click': ()=>{
                                            this.downFile(params.row)
                                        },
                                    }
                                }, '下载')
                            ])
                        }
                    },
                ], 
            }
        },
        created(){

        },
        mounted(){

        },
        methods:{
            downFile(row){
                let windowsUrl = window.location.href
                windowsUrl = windowsUrl.split('//')
                let getIp = windowsUrl[1].split('/')[0]
                getIp = getIp.split(':')[0]
                var objurl = `${getIp}/Learn/${row.path}`;
                // 处理下载地址与当前网站不同源，download属性不生效的问题
                const x = new window.XMLHttpRequest();
                x.open('GET', `http://${objurl}`, true);
                x.responseType = 'blob';
                x.onload = () => {
                    const url = window.URL.createObjectURL(x.response);
                    const a = document.createElement('a');
                    a.href = url;
                    a.download = row.name;
                    a.click();
                };
                x.send();
            },
        }
    }
</script>
<style scoped>
    
</style>
